package com.foo.web.controller;

import com.foo.entity.SysUser;
import com.foo.service.SysUserService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;


@RestController
@Api(tags = "用户管理")
@RequestMapping("user")
public class UserController {
    @Autowired
    private SysUserService sysUserService;

    @ApiOperation(value = "查询全部用户",notes = "查询全部用户")
    @GetMapping("queryAll")
    public List<SysUser> queryAll(){
        return sysUserService.queryAll();
    }

    @ApiOperation(value = "查询用户详细信息",notes = "查询用户详细信息")
    @GetMapping("queryInfo")
    public SysUser quertInfo(Long id){
        return sysUserService.selectInfo(id);
    }

    @PostMapping("login")
    public ResponseEntity Login(@RequestBody SysUser user, HttpServletRequest request){
        SysUser loguser = sysUserService.login(user.getUserName(), user.getPassword());
        if(loguser != null){
            return ResponseEntity.ok(loguser);
        }
        return ResponseEntity.ok(null);
    }
}

